//
//  SearchBarView.m
//  Arts1
//
//  Created by lanou on 15/8/29.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "SearchBarView.h"
#import "PrefixHeader.pch"

@implementation SearchBarView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor= [UIColor whiteColor];
//        _searchBar = [[UISearchBar alloc] initWithFrame:self.bounds];
        _searchBar = [[UISearchBar alloc] init];
        [_searchBar setFrame:(CGRectMake(2, 5, SCREEN_WIDTH - 4, 34))];
        _searchBar.searchBarStyle = UISearchBarStyleDefault;
        _searchBar.placeholder = @"search";
        _searchBar.delegate = self;
        _searchBar.showsCancelButton = NO;
        
        // UISearchBar 有两个的子视图有两个姿势图，一个是背景视图，一个是textfield
        [self addSubview:_searchBar];
        UIView *view = _searchBar.subviews[0];
        [view.subviews[0] removeFromSuperview];
        UITextField *textfield = (UITextField *)view.subviews[0];
        textfield.backgroundColor = kCustomColor(230, 230, 230, 1);
  
        for(id cc in [_searchBar subviews]){
            if([cc isKindOfClass:[UIButton class]]){
                UIButton *btn = (UIButton *)cc;
                [btn setTitle:@"C" forState:UIControlStateNormal];
            }  
        }
        
        
    }
    return self;
}

// 创建搜索结果展示视图
- (void)createSearchResultView{
    _resultView = [[SearchCourseTableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 0) style:(UITableViewStylePlain)];
    [self addSubview:_resultView];
    
}


- (void) searchBarCancelButtonClicked:(UISearchBar *)searchBar{
    _searchBar.text = @"";
    [_searchBar resignFirstResponder];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
